# 此工具类为装换mongoose属性专用

_ = require 'underscore'

module.exports = (attributes, values) ->
  attributes = _.mapObject attributes, (v, k) ->
    switch v.type
      when "Array" # 替换Array属性为Array（应该是mongoose的bug，不能用字符串Array）
        v.type = Array
        values[k] = _.without(values[k].split(','), ',', '') if values
      when "Image" # 替换自定义Image属性为String
        v.type = 'String'
      when "ImageArray" # 替换自定义ImageArray属性为[String]
        v.type = [String]
        values[k] = _.without(values[k].split(','), ',', '') if values
      when "Mixed"
        v.type = {}
      else
        v.type = v.type
